//
//  RID.m
//  SimulacraDB
//
//  Created by Andre Cohen on 8/21/08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "RID.h"


@implementation RID

@synthesize value;

+ (RID *)createWithValue:(UInt64)value {
	RID *rid = [[[RID alloc] init] autorelease];
	[rid setValue:value];
	return rid;
}

+ (RID *)createWithPage:(int)pageNumber offset:(int)pageOffset {
	return [RID createWithValue:((UInt64)pageNumber<<32) | pageOffset];
}

- (RID *)clone {
	return [RID createWithPage:[self page] offset:[self offset]];
}

- (NSString *)description {
	return [NSString stringWithFormat:@"%d.%d",[self page],[self offset]];
}

- (int)page {
	return value>>32;
}

- (void)setPage:(int)page {
	value = ((UInt64)page<<32) | [self offset];
}

- (int)offset {
	return (int)value;
}

- (void)setOffset:(int)offset {
	value = ((UInt64)[self page]<<32) | offset;
}

- (BOOL)equalTo:(id)object {
	return ([self page]==[(RID *)object page]) && ([self offset]==[(RID *)object offset]);
}

@end
